<extend name="Layout/ins_popup" />
<block name="content">
	<input type="hidden" name="ajax" id="ajax" value="1">
	<div class="popup-frame">		
		<div class="popup-header">
			<div class="pull-left">
				<h1>添加</h1>
			</div>
			<div class="pull-right">
				<a id="save" class="btn" >确定</a>
				<a id="close" class="btn btn-cancel">关闭</a>
			</div>
		</div>
		<div class="popup-body">
			<div class="popup-body-scroll">
				<div class="popup-content">
					<form id="form_data" name="form_data" method="post" >
						<input type="hidden" name="id" id="id" >
						<input type="hidden" name="opmode" id="opmode" value="add">
						<input type="hidden" name="admin" id="admin">
						<input type="hidden" name="write" id="write">
						<input type="hidden" name="read" id="read">
						<input type="hidden" name="controller" value="{$controller}">
						<div class="layui-form-item">
							<label class="layui-form-label" for="name">名称*：</label>
							<div class="layui-input-block">
								<input class="layui-input" type="text" id="name" name="name" check="required" info="请输入名称">
							</div>
						</div>
						<if condition="$has_pid">
							<div class="layui-form-item">
								<label class="layui-form-label" for="folder_name">父节点*：</label>
								<div class="layui-input-block">
									<div class="input-group">
										<input type="hidden" name="pid" id="pid">
										<input name="folder_name" class="layui-input val" id="folder_name" type="text" info="请选择父节点" check="required" />
										<a class="add-on" id="btn_select_pid"> 选择 </a>
									</div>
								</div>
							</div>
						</if>
						<div class="layui-form-item">
							<label class="layui-form-label" for="folder_name">管理：</label>
							<div class="layui-input-block">
								<div id="admin_list" class="input-box">
									<a class="add-on select_auth"><i class="fa fa-user"></i></a>
									<div class="wrap" >
										<span class="address_list"></span>
										<span class="text" >
											<input class="letter" type="text">
										</span>
									</div>
									<div class="search dropdown ">
										<ul class="dropdown-menu"></ul>
									</div>
								</div>
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label" for="folder_name">编辑：</label>
							<div class="layui-input-block">
								<div id="write_list" class="input-box">
									<a class="add-on select_auth" > <i class="fa fa-user"></i> </a>
									<div class="wrap" >
										<span class="address_list"></span>
										<span class="text" >
											<input class="letter" type="text"  >
										</span>
									</div>
									<div class="search dropdown ">
										<ul class="dropdown-menu"></ul>
									</div>
								</div>
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label" for="folder_name">读取：</label>
							<div class="layui-input-block">
								<div id="read_list" class="input-box">
									<a class="add-on select_auth"> <i class="fa fa-user"></i> </a>
									<div class="wrap" >
										<span class="address_list"></span>
										<span class="text" >
											<input class="letter" type="text"  >
										</span>
									</div>
									<div class="search dropdown ">
										<ul class="dropdown-menu"></ul>
									</div>
								</div>
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label" for="sort">排序：</label>
							<div class="layui-input-block col-10">
								<input class="layui-input" type="text" id="sort" name="sort" >
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label" for="sort">状态：</label>
							<div class="layui-input-block col-10 x-select">
								<select class="layui-input"  name="is_del" id="is_del">
									<option value="0">启用</option>
									<option value="1">禁用</option>
								</select>
							</div>
						</div>
					</form>
				</div>
			</div>
		</div>
	</div>
</block>
<block name="js">
	<script type="text/javascript">
		var index = parent.layer.getFrameIndex(window.name);
		layui.use(['global'], function() {
			var $ = layui.jquery;

			//保存后关闭
			$('#save').on('click', function() {
				$("#admin").val("");
				$("#admin_list span.address_list span").each(function() {
					$("#admin").val($("#admin").val() + $(this).text().replace(';', '') + '|' + $(this).attr("data") + ";");
				});

				$("#write").val("");
				$("#write_list span.address_list span").each(function() {
					$("#write").val($("#write").val() + $(this).text().replace(';', '') + '|' + $(this).attr("data") + ";");
				});

				$("#read").val("");
				$("#read_list span.address_list span").each(function() {
					$("#read").val($("#read").val() + $(this).text().replace(';', '') + '|' + $(this).attr("data") + ";");
				});

				check_form("form_data", function(ret) {
					if (ret.status == 1) {
						var vars = $("#form_data").serialize();
						send_ajax("{:U('SystemFolder/save')}", vars, function(data) {
							if (data.status) {
								parent.layer.msg(data.info, function() {
									parent.location.reload(true);
								});
							} else {
								parent.layer(ret.info);
								return false;
							}
						});
					} else {
						layer.msg(ret.info);
						ret.dom.focus();
						return false;
					}
				});
			});

			//关闭iframe
			$('#close').click(function() {
				parent.layer.close(index);
			});

			$('.select_auth').on('click', function() {
				winopen("{:U('popup/auth')}", 560, 470);
			});

			$('#btn_select_pid').on('click', function() {
				winopen("{:U('SystemFolder/winpop','controller='.$controller)}", 560, 470);
			});

			$(document).on("click", ".inputbox .address_list a.del", function() {
				$(this).parent().parent().remove();
			});
		});

	</script>
</block>